<!--
* @Author: zhangjing
* @Date: 2025-04-07 16:51:29
* @Description: 医护管理=>
-->
<template>
  <pro-table
    ref="protable"
    rowKey="doctorId"
    :loadDataUrl="api.getList"
    :columns="columns"
    :isAdd="$_has('hosp:docterNurses:insert')"
    :isDelete="$_has('hosp:docterNurses:delete')"
    :orgId="globalOrgId"
    :isRowSelection="false"
    :extendParam="{
      orgId: globalOrgId,
    }"
    :isImport="$_has('hosp:docterNurses:import')"
    :isDefinedFilter="false"
    @selectedRowChange="onSelectChange"
    @addRecord="addRecord"
    @showDeleteConfirm="showDeleteConfirm"
    @changeSelect="changeSelect"
    @handlerReset="handlerReset"
    @importRecord="importRecord"
  >
    <div slot="photoPath" slot-scope="{ text, record }" style="width: 60px; height: 60px; overflow: hidden; border-radius: 100%; margin: 0 auto">
      <img v-if="text" :src="fileUrl + text.split(';')[0]" style="width: 80px" />
    </div>
    <a-tag :color="text == 1 ? '#00a095' : '#d43030'" slot="status" slot-scope="{ text, record }">{{ record.statusName }}</a-tag>
    <span slot="operation" slot-scope="{ text, record }" class="operation">
      <a href="javascript:;" v-has="'hosp:docterNurses:update'" title="编辑" class="edit" @click="editRecord(record)">编辑</a>

      <a href="javascript:;" v-has="'hosp:docterNurses:delete'" title="删除" class="del" @click="showDeleteConfirm(1, record.doctorId, record.realName)">删除</a
      ><a href="javascript:;" v-if="hasAddOperation(record)" title="随访患者" class="edit" @click="details(record)">随访患者</a>
    </span>
    <!-- 添加，编辑 -->
    <add-or-edit-doctor-modal ref="addOrEditModal" :api="api" modalTitle="账户" @ok="handlerRefresh"></add-or-edit-doctor-modal>
    <accountModal ref="accountModal"></accountModal>
    <imporDoctorModal ref="imporDoctorModal" @ok="handlerRefresh"></imporDoctorModal>
  </pro-table>
</template>

<script>
import { filterOption, filterName } from "@/utils/base.js";
import { rowSelection, recordOperation } from "@/mixins";
import { doctorManageapi, sysManageapi } from "@/api/index.js";
import addOrEditDoctorModal from "./module/addOrEditDoctorModal";
import accountModal from "./module/accountModal.vue";
import imporDoctorModal from "./module/imporDoctorModal.vue";
import { mapState, mapMutations, mapActions } from "vuex";
const columns = [
  {
    title: "所属医院",
    dataIndex: "deptName", // data数据源中对应的字段
    key: "deptName", // 列的关键字 如果有 dataIndex 则不需要key
    ellipsis: true,
    width: 140,
    searchInfo: {
      type: "treeSelect",
      value: "deptId",
      text: "所属医院",
      defaultValue: undefined,
      optionlist: [],
      isLinkage: true // 是否联动筛选
    }
  },

  {
    title: "姓名",
    dataIndex: "realName",
    key: "realName",
    searchInfo: {
      type: "string",
      defaultValue: ""
    }
  },

  {
    title: "电话",
    dataIndex: "phone",
    key: "phone",
    searchInfo: {
      type: "string",
      defaultValue: ""
    },
    width: 120
  },
  {
    title: "执业医师、护士证号",
    dataIndex: "licenseNumber",
    key: "licenseNumber",
    width: 200,
    searchInfo: {
      type: "string",
      defaultValue: ""
    }
  },
  {
    title: "性别",
    dataIndex: "gender",
    key: "gender",
    ellipsis: true
  },

  {
    title: "出生年月",
    dataIndex: "birth",
    key: "birth",
    ellipsis: true,
    width: 120,
    customRender: function (t, r, index) {
      return r.birth ? r.birth.slice(0, 10) : "";
    }
  },
  {
    title: "职称",
    dataIndex: "position",
    key: "position",
    ellipsis: true
  },
  {
    title: "学历",
    dataIndex: "educationName",
    key: "educationName"
  },

  {
    title: "在职状态",
    dataIndex: "status",
    key: "status",
    scopedSlots: {
      customRender: "status"
    }
  },
  {
    title: "操作",
    key: "operation",
    scopedSlots: {
      customRender: "operation"
    },
    width: 200,
    fixed: "right"
  }
];
export default {
  name: "Studentlist",
  mixins: [rowSelection, recordOperation],
  components: {
    addOrEditDoctorModal,
    accountModal,
    imporDoctorModal
  },
  data () {
    return {
      columns,
      api: doctorManageapi.doctorUrl,
      form: this.$form.createForm(this),
      replaceFields: { children: "children", title: "deptName", key: "deptId", value: "deptId" },
      fileUrl: process.env.VUE_APP_FILE_API
    };
  },
  computed: {},
  watch: {
    globalOrgId: {
      handler (newval, oldval) {
        this.$nextTick(() => {
          this.handlerRefresh();
        });
      },
      immediate: true, // 刷新加载 立马触发一次handler
      deep: true
    }
  },
  created () {
    this.columns = columns.filter((item) => {
      if (!(!this.isAdmin && item.key == "deptName")) {
        return item;
      }
    });
  },
  methods: {
    setTableData (list) {
      this.tablelist = [...list];
    },

    changeSelect (e, value, item) {},

    // 切换校区
    changeDept (value) {
      console.log(JSON.stringify(value));
      this.filter.deptId = value;
    },

    /* 筛选拦截，如果不需要特殊处理筛选条件，可以不做设置 */
    handlerSearch (obj) {
      this.$refs.protable && this.$refs.protable.loadTable(this.filter);
    },
    /* 刷新列表当前页 */
    handlerRefresh () {
      this.$refs.protable && this.$refs.protable.handlerRefresh();
    },
    /* 筛选条件重置, 将默认设置为undefined/[] */
    handlerReset (obj) {
      console.log("obj" + JSON.stringify(obj));
      let newcolumns = [...this.columns];
      for (var key in obj) {
        console.log(typeof obj[key]);
        if (["string", "number"].includes(typeof obj[key])) {
          newcolumns = this.setColumnsSearchInfo(newcolumns, key, undefined, "defaultValue");
        } else {
          if (Array.isArray(obj[key])) {
            newcolumns = this.setColumnsSearchInfo(newcolumns, key, [], "defaultValue");
          }
        }
      }
      this.columns = [...newcolumns];
      this.orgId = "";
      this.$nextTick(() => {
        this.$refs.protable.loadTable({});
      });
    },
    details (info) {
      this.$refs.accountModal.show(info);
    },
    importRecord () {
      this.$refs.imporDoctorModal.show();
    },
    hasAddOperation (row) {
      if (this.$_has("hosp:docterNurses:list")) {
        return true;
      }
      // 如果是医生权限，且是自己用户，也可以显示
      if (this.isDoctor && row.userId == this.userinfo.userId) {
        return true;
      }
      return false;
    }
  }
};
</script>

<style scoped="scoped" lang="less">
.avatar {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  display: block;
  margin: 0 auto;
}
.topbar {
  background: #fff;
  z-index: 6;
  -webkit-box-shadow: 0px 4px 8px rgba(19, 29, 53, 0.05);
  box-shadow: 0px 4px 8px rgba(19, 29, 53, 0.05);
  border-radius: 8px;
  margin: 0;
  margin-bottom: 10px;
  -webkit-transition: all 0.3s;
  transition: all 0.3s;
  .toolbar .refresh {
    width: 40px;
    font-size: 14px;
    margin-right: 10px;
  }
  .toolbar .ant-btn {
    width: 95px;
    font-size: 14px;
    & + .ant-btn {
      margin-left: 10px;
    }
  }

  .toolbar .ant-btn-blue .iconfont,
  .toolbar .ant-btn-green .iconfont,
  .toolbar .ant-btn-yellow .iconfont,
  .toolbar .ant-btn-primary .iconfont {
    font-size: 12px;
    margin-right: 5px !important;
  }
}
</style>
